//
//  ReportView.m
//  TILLiveSDKShow
//
//  Created by wilderliao on 17/2/6.
//  Copyright © 2017年 Tencent. All rights reserved.
//

#import "ReportView.h"
#import "UIImage+MultiFormat.h"

@implementation ReportView


- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _bgimageView = [[UIImageView alloc] init];
        _bgimageView.image = [UIImage imageNamed:@"viedo_link_head_background"];
        
        [self addSubview:_bgimageView];
        
        _headerBtn = [UIButton buttonWithType:UIButtonTypeCustom];

        [_headerBtn addTarget:self action:@selector(headerBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_headerBtn];
        
        _nameLab = [[UILabel alloc] init];
        _nameLab.textColor = [UIColor whiteColor];
        _nameLab.font = FontP(15);
        _nameLab.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_nameLab];
        
        
        _sexLab = [[UILabel alloc] init];
        _sexLab.textColor = [UIColor whiteColor];
        _sexLab.font = FontP(13);
        _sexLab.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_sexLab];
        
        _addressimg = [[UIImageView alloc] init];
        _addressimg.image = [UIImage imageNamed:@"viedo_link_location_icon"];
        [self addSubview:_addressimg];
        
        _addressLab =[[UILabel alloc] init];
        _addressLab.textColor = [UIColor whiteColor];
        _addressLab.font = FontP(13);
        _addressLab.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_addressLab];
        
        _distanceLab =[[UILabel alloc] init];
        _distanceLab.textColor = [UIColor whiteColor];
        _distanceLab.font = FontP(13);
        _distanceLab.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_distanceLab];
        
        
    
        _AddbuddyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_AddbuddyBtn setBackgroundImage:[UIImage imageNamed:@"viedo_link_follow_icon"] forState:UIControlStateNormal];
        _AddbuddyBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _AddbuddyBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
        [_AddbuddyBtn setTitle:@"加好友" forState:UIControlStateNormal];
        [_AddbuddyBtn addTarget:self action:@selector(AddbuddyBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
            NSLog(@"ipad");
            _AddbuddyBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 25);
            _AddbuddyBtn.titleLabel.font = FontP(16);
            
        }else{
            _AddbuddyBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
            _AddbuddyBtn.titleLabel.font = FontP(14);
            
            NSLog(@"iphone or ipod");
        }
        [self addSubview:_AddbuddyBtn];
        
        
        _reportBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_reportBtn setBackgroundImage:[UIImage imageNamed:@"viedo_link_hold_icon"] forState:UIControlStateNormal];
        _reportBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _reportBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
        [_reportBtn addTarget:self action:@selector(reportBtnClickAction:) forControlEvents:UIControlEventTouchUpInside];
        _reportBtn.titleLabel.font = FontP(14);

        [_reportBtn setTitle:@"举报" forState:UIControlStateNormal];
        [self addSubview:_reportBtn];
        
        

        
        
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}







- (void)AddbuddyBtnAction:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(AddbuddyBtnAction:)]) {
        [self.delegate AddbuddyBtnAction:sender];
    }

}

- (void)reportBtnClickAction:(UIButton *)sender{

    if ([self.delegate respondsToSelector:@selector(reportBtnClickAction:)]) {
        [self.delegate reportBtnClickAction:sender];
    }
}

- (void)headerBtnClick:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(headerBtnClick:)]) {
        [self.delegate headerBtnClick:sender];
    }

}

-(void)setModel:(CheekVodeModel *)model{
    
    _model = model;
    
    [_bgimageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.top.width.equalTo(self);
        make.height.mas_equalTo(44*SCREEN_WIDTH_RATIO47);
    }];
    
    
    [_headerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.top.equalTo(self);
        make.width.height.mas_equalTo(44*SCREEN_WIDTH_RATIO47);
    }];
    _headerBtn.layer.masksToBounds = YES;
    _headerBtn.layer.borderWidth = 1;
    _headerBtn.layer.borderColor = [[UIColor whiteColor] CGColor];
    _headerBtn.layer.cornerRadius = 22*SCREEN_WIDTH_RATIO47;//设置那个圆角的有多圆
    
    [_nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_headerBtn.mas_right).offset(7.5*SCREEN_WIDTH_RATIO47);
        make.top.equalTo(self);
        make.height.mas_equalTo(22*SCREEN_WIDTH_RATIO47);
    }];
    
    [_sexLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_headerBtn.mas_right).offset(7.5*SCREEN_WIDTH_RATIO47);
        make.top.equalTo(_nameLab.mas_bottom).offset(5*SCREEN_WIDTH_RATIO47);
        make.height.mas_equalTo(17*SCREEN_WIDTH_RATIO47);
    }];
    
    [_addressimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_sexLab.mas_right).offset(7.5*SCREEN_WIDTH_RATIO47);
        make.top.equalTo(_nameLab.mas_bottom).offset(8*SCREEN_WIDTH_RATIO47);
        make.height.mas_equalTo(13*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo(8*SCREEN_WIDTH_RATIO47);
    }];
    
    [_addressLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_addressimg.mas_right).offset(7.5);
        make.top.equalTo(_nameLab.mas_bottom).offset(5);
        make.height.mas_equalTo(17*SCREEN_WIDTH_RATIO47);
    }];
    
    [_distanceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_distanceLab.mas_right).offset(7.5);
        make.top.equalTo(_nameLab.mas_bottom).offset(5);
        make.height.mas_equalTo(17*SCREEN_WIDTH_RATIO47);
    }];
    
    [_AddbuddyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.top.equalTo(_bgimageView.mas_bottom).offset(20);
        make.height.mas_equalTo(34*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo(100*SCREEN_WIDTH_RATIO47);
    }];
    
    [_reportBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_AddbuddyBtn.mas_right).offset(15);
        make.top.equalTo(_bgimageView.mas_bottom).offset(20);
        make.height.mas_equalTo(34*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo(90*SCREEN_WIDTH_RATIO47);
    }];
    
    
        [_headerBtn setImage:[UIImage sd_imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:HttpImgUrl(_model.photo)]]] forState:UIControlStateNormal];
    
        
    
        self.nameLab.text = _model.nickName;
    
        if ([_model.sex isEqualToString:@"1"]) {
            self.sexLab.text = @"男";
        }else{
            self.sexLab.text = @"女";
        }
        self.addressLab.text = _model.location;
        self.distanceLab.text = _model.distance;

}


@end
